<?PHP
class sys{
  static function includeContent(){
    global $currentpage;
    $currentpage->getContent();
  }

  static function includeHeader(){
    global $currentpage;
    echo "<title>".$currentpage->title."</title>";
    $rows = $GLOBALS['db']->ReadRows("SELECT name, content
                        FROM {'dbprefix'}meta_global
                        UNION SELECT name, content
                        FROM {'dbprefix'}meta_local
                        WHERE page = '".$currentpage->id."'");
    if($rows){
      foreach($rows as $row){
        echo "<meta name=\"".htmlentities($row->name)."\" content=\"".htmlentities($row->content)."\" />";
      }
    }
    echo $currentpage->getEditor()->getHeader();
    EventManager::raiseEvent("header_included",".",null);
  }

  static function displayBreadcrumb($separator,$class,$idpraefix){
    global $currentpage;
    $currentpage->displayBreadcrumb($separator,$class,$idpraefix);
  }
  
  static function displayMenu($id, $globalstart,$globalend, $elementstart,$elementend,
                       $class){
    Menu::display($id, $globalstart,$globalend, $elementstart,$elementend,$class);
  }

  static function displayGlobalMenu($globalstart,$globalend, $elementstart,$elementend,
                       $class){
       Menu::display(Settings::getInstance()->get("mainmenu"),
                     $globalstart,
                        $globalend,
                     $elementstart,
                     $elementend,
                     $class);
  }
 
  static function displayLocalMenu($globalstart,$globalend, $elementstart,$elementend,
                       $class){
    global $currentpage;
    if($currentpage->menu > -1){
      Menu::display($currentpage->menu, $globalstart,$globalend, $elementstart,$elementend,$class);
    }
  }

  static function getColor($area,$areaType,$id){
    return "#".Settings::getInstance()->specify($areaType,$area)->get("skin".$id);
  }

  static function localMenuExists(){
    global $currentpage;
    if($currentpage->menu){
      return true;
    }
    else{
      return false;
    }
  }
  
  static function getTitle(){
    return  Settings::getInstance()->get("title");
  }
   
  static function getFullSkinPath(){
    return Settings::getInstance()->get("host")."/".SkinController::getCurrentSkinPath()."/";
  }

  static function getMenues($dir){
    $dir = $GLOBALS['db']->EscapeString($dir);
    return $GLOBALS['db']->ReadRows("SELECT id, name, (
                                       SELECT COUNT( * ) 
                                       FROM {'dbprefix'}menu
                                       WHERE menuID = {'dbprefix'}menu_names.id
                                     )count
                                     FROM `{'dbprefix'}menu_names`
                                     WHERE dir = '".$dir."'");
  }

  public static function getAllMenues(){
    return $GLOBALS['db']->ReadRows("SELECT id, name, (
                                       SELECT COUNT( * ) 
                                       FROM {'dbprefix'}menu
                                       WHERE menuID = {'dbprefix'}menu_names.id
                                     )count
                                     FROM `{'dbprefix'}menu_names`");
  }

  static function getFooter(){
    return "Hilfe | ContentLion V 1.0.0 (Alpha 1)";
  }

  static function getCurrentUserName(){
    $res = "";
    if(isset($_SESSION['user'])){
      $res = $_SESSION['user']->name;
    }
    return $res;
  }

  public static function parseGetParams(){
    $pos = strpos($_SERVER['REQUEST_URI'],'?');
    foreach(explode("&", substr($_SERVER['REQUEST_URI'], $pos + 1, strlen($_SERVER['REQUEST_URI']) - 8)) as $param){
      $splitter = explode('=', $param);
      if(sizeOf($splitter) > 1){
        $_GET[$splitter[0]] = urldecode($splitter[1]);
        if(strpos($_GET[$splitter[0]], "&#") !== false){
          $_GET[$splitter[0]] = urldecode($splitter[1]);
        }
      }
    }
  }
}
?>